#include "../include/NewFileDialog.h"

//(*InternalHeaders(NewFile)
#include <wx/settings.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/statbmp.h>
#include <wx/image.h>
//*)

//(*IdInit(NewFile)
const long NewFileDialog::ID_STATICTEXT1 = wxNewId();
const long NewFileDialog::ID_CUSTOM1 = wxNewId();
const long NewFileDialog::ID_STATICTEXT2 = wxNewId();
const long NewFileDialog::ID_CUSTOM3 = wxNewId();
const long NewFileDialog::ID_STATICTEXT3 = wxNewId();
const long NewFileDialog::ID_CUSTOM2 = wxNewId();
const long NewFileDialog::ID_STATICTEXT4 = wxNewId();
const long NewFileDialog::ID_CUSTOM4 = wxNewId();
const long NewFileDialog::ID_STATICBITMAP1 =  wxNewId();
//*)

BEGIN_EVENT_TABLE(NewFileDialog,wxDialog)
	//(*EventTable(NewFile)
	//*)
	EVT_BUTTON(wxID_OK, NewFileDialog::OnButtonOKClick)
	EVT_BUTTON(wxID_CANCEL, NewFileDialog::OnButtonCancelClick)
END_EVENT_TABLE()

NewFileDialog::NewFileDialog(wxWindow* parent, Config* config, wxWindowID id)
{
    this->config = config;

    wxArrayString array;
    array.Add( _("e") );
    array.Add( _("-") );

    wxTextValidator numberValidator(wxFILTER_NUMERIC | wxFILTER_EXCLUDE_CHAR_LIST);
    numberValidator.SetExcludes( array );

	//(*Initialize(NewFileDialog)
	wxStaticBoxSizer* StaticBoxSizer2;
	wxFlexGridSizer* FlexGridSizer4;
	wxFlexGridSizer* FlexGridSizer3;
	wxFlexGridSizer* FlexGridSizer2;
	wxStaticBoxSizer* StaticBoxSizer3;
	wxBoxSizer* BoxSizer1;
	wxStaticBoxSizer* StaticBoxSizer1;
	wxFlexGridSizer* FlexGridSizer1;

	Create(parent, wxID_ANY, _("New"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
	SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT));
	SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
	FlexGridSizer1 = new wxFlexGridSizer(2, 1, 0, 0);
	FlexGridSizer1->AddGrowableCol(0);
	FlexGridSizer1->AddGrowableRow(0);
	StaticBitmap1 = new wxStaticBitmap(this, ID_STATICBITMAP1, wxBitmap(wxImage(_T("..\\bin\\data\\logo.png"))), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP1"));
	FlexGridSizer1->Add(StaticBitmap1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer4 = new wxFlexGridSizer(0, 3, 0, 0);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("Properties"));
	StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, this, _("Dimension"));
	FlexGridSizer2 = new wxFlexGridSizer(2, 2, 0, 0);
	FlexGridSizer2->AddGrowableCol(0);
	FlexGridSizer2->AddGrowableRow(0);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Width:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	FlexGridSizer2->Add(StaticText1, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
	TextFieldWidth = new wxTextCtrl(this,ID_CUSTOM1, _("720"), wxDefaultPosition, wxDefaultSize,0 , numberValidator,_T("ID_CUSTOM1"));
	FlexGridSizer2->Add(TextFieldWidth, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Height:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	FlexGridSizer2->Add(StaticText2, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
	TextFieldHeight = new wxTextCtrl(this,ID_CUSTOM3, _("405"), wxDefaultPosition, wxDefaultSize,0 , numberValidator,_T("ID_CUSTOM3"));
	FlexGridSizer2->Add(TextFieldHeight, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer2->Add(FlexGridSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer1->Add(StaticBoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer3 = new wxStaticBoxSizer(wxVERTICAL, this, _("Movie"));
	FlexGridSizer3 = new wxFlexGridSizer(2, 2, 0, 0);
	FlexGridSizer3->AddGrowableCol(0);
	FlexGridSizer3->AddGrowableRow(0);
	StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Length (sec):"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	FlexGridSizer3->Add(StaticText3, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
	TextFieldLength = new wxTextCtrl(this,ID_CUSTOM2, _("10"), wxDefaultPosition, wxDefaultSize,0 , numberValidator,_T("ID_CUSTOM2"));
	FlexGridSizer3->Add(TextFieldLength, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText4 = new wxStaticText(this, ID_STATICTEXT4, _("FPS:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
	FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
	TextFieldFPS = new wxTextCtrl(this,ID_CUSTOM4, _("30"), wxDefaultPosition, wxDefaultSize,0 , numberValidator,_T("ID_CUSTOM4"));
	FlexGridSizer3->Add(TextFieldFPS, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer3->Add(FlexGridSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer1->Add(StaticBoxSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer4->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	ButtonOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("wxID_OK"));
	ButtonOK->SetDefault();
	ButtonOK->SetFocus();
	BoxSizer1->Add(ButtonOK, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	ButtonCancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("wxID_CANCEL"));
	BoxSizer1->Add(ButtonCancel, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer4->Add(BoxSizer1, 1, wxALL|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL, 5);
	FlexGridSizer1->Add(FlexGridSizer4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->Fit(this);
	FlexGridSizer1->SetSizeHints(this);
	//*)

    TextFieldHeight->SetMaxLength(4);
    TextFieldWidth->SetMaxLength(4);
    TextFieldFPS->SetMaxLength(2);
    TextFieldLength->SetMaxLength(4);
}

NewFileDialog::~NewFileDialog()
{

}


void NewFileDialog::OnButtonOKClick(wxCommandEvent& event)
{
    long int w, h, FPS, length;
    TextFieldWidth->GetValue().ToLong( &w );
    TextFieldHeight->GetValue().ToLong( &h );
    TextFieldFPS->GetValue().ToLong( &FPS );
    TextFieldLength->GetValue().ToLong( &length );
    config->setCanvasSize( w, h );
    config->setFPS( FPS );
    config->setLength( length );

    SetReturnCode(1);
    Destroy();
}

void NewFileDialog::OnButtonCancelClick(wxCommandEvent& event)
{
    SetReturnCode(0);
    Destroy();
}
